package com.feng.stateAnalysis
{
	import com.feng.data.StateData;
	import com.feng.debug.logger;

	/**
	 * 属性最大者受击分析
	 * @author 风之守望者
	 * 2013-4-14
	 */
	public class AttackMaxAnalysis
	{
		private var stateData:StateData;

		public function AttackMaxAnalysis(stateData:StateData)
		{
			this.stateData = stateData;
		}

		public function onBattleStart(myId:int):void
		{
			stateData.totalAttackNum = 0;
			stateData.hasMaxAttackNum = 0;
			stateData.attackMaxAttackNum = 0;
			stateData.hasMaxSpeedNum = 0;
			stateData.attackMaxSpeedNum = 0;
		}

		public function onAnyoneAttack(state:Array, myId:int, attackerId:int, targetId:int):void
		{
			stateData.totalAttackNum++;

			var attackSort:Array = state.concat();
			attackSort.sort(function(x:*, y:*):Number
			{
				if (x.hp == 0 || y.hp == 0)
					return y.hp - x.hp;
				return y.atk - x.atk;
			});
			
			if (attackSort[0].atk > attackSort[1].atk)
			{
				stateData.hasMaxAttackNum++;
				if (attackSort[0].id == targetId)
					stateData.attackMaxAttackNum++;
			}

			var speedSort:Array = state.concat();
			speedSort.sort(function(x:*, y:*):Number
			{
				if (x.hp == 0 || y.hp == 0)
					return y.hp - x.hp;
				return y.spd - x.spd;
			});
			if (speedSort[0].spd > speedSort[1].spd)
			{
				stateData.hasMaxSpeedNum++;
				if (speedSort[0].id == targetId)
					stateData.attackMaxSpeedNum++;
			}

		}

		public function onBattleFinish(totalBattles:int, myVectories:int):void
		{
			logger("总攻击次数：" + stateData.totalAttackNum);
			logger("最高攻击受击率：" + stateData.attackMaxAttackNum + "/" + stateData.hasMaxAttackNum);
			logger("最高速度受击率：" + stateData.attackMaxSpeedNum + "/" + stateData.hasMaxSpeedNum);
		}
	}
}
